package myutils

import (
	"net/http"
	"server/global"
	"server/model"

	"github.com/gin-gonic/gin"
)

//统一json数据返回格式
func ResultJSON(ctx *gin.Context, code int, data interface{}) {
	var res = &model.StandardResponse{
		Status:  code,
		Message: global.GetStatusMes(code),
		Data:    data,
	}
	if data == nil {
		ctx.JSON(http.StatusOK, map[string]interface{}{
			"status":  res.Status,
			"message": res.Message,
		})
		return
	}
	ctx.JSON(http.StatusOK, map[string]interface{}{
		"status":  res.Status,
		"message": res.Message,
		"data":    res.Data,
	})

}
